package alo;

import java.util.*;

/**
 * @ClassName t4
 * @Description 美团笔试题，链表+链表的结构，对Collections的运用
 * @Author Fanxc
 * @DATE 2021/4/20 9:25
 * @Version 1.0
 */
public class t5 {
    static class Node{
        int  key,val;
        List<Integer> list=new LinkedList<>();
        public Node(int key,int val) {
            this.key=key;
            this.val = val;
            list.add(val);
        }
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        List<Node> list=new LinkedList<>();
        Map<Character,Node> map=new HashMap<>();
        int nums= sc.nextInt();
        int index=0;
        for (int i = 0; i < nums; i++) {
            int select= sc.nextInt();
            if (select==1){
                int n= sc.nextInt();
                char s=sc.next().toCharArray()[0];
                //添加
                if (map.containsKey(s)){
                    map.get(s).list.add(n);
                }else {
                    Node node = new Node(index++,n);
                    map.put(s,node);
                    list.add(node);
                }
            }else {
                char s1=sc.next().toCharArray()[0];
                char s2=sc.next().toCharArray()[0];
                //交换
                Collections.swap(list,map.get(s1).key,map.get(s2).key);
                int temp=map.get('a').key;
                map.get('a').key=map.get('b').key;
                map.get('b').key=temp;
            }
        }
        //输出
        for (Node node:list) {
            for (Integer i :
                    node.list) {
                System.out.println(i);

            }
        }
    }
}
